package org.bigstones.orgnzr.model.impl.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import org.bigstones.orgnzr.model.impl.jpa.entities.User;

public class PlanDao {

//	public 
	
	
	public void registerUser() throws Exception{
		EntityManager em = null;
		try{
			em = EMF.get().createEntityManager();
			User u = new User();
			u.setFirstName("John");
			u.setLastName("Jameson");
			u.setUserId("john.jameson@gmail.com");
			
			EntityTransaction t = em.getTransaction();
			t.begin();
			
			em.persist(u);
			t.commit();
			
		}catch(Throwable t){
			throw new Exception(t);
		}finally{
			if(em!= null) em.close();
		}
	}
	
//	public int getUsersCount() throws Exception{
//		EntityManager em = null;
//		try{
//			em = EMF.get().createEntityManager();
//			Query q = em.createQuery("Select u from User u");
//			
//			return q.getResultList().size();
//		}catch (Throwable e) {
//			throw new Exception(e);
//		}finally{
//			if(em != null) em.close();
//		}
//	}
}
